declare interface MetaInfo {
  title?: string;
  keywords?: string;
  description?: string;
}

// 更新meta
export function updateMetaInfo(meta: MetaInfo) {
  document.title = meta.title || '官网';

  if (meta.keywords) {
    const keywordsTagTemp = document.querySelector('meta[name="keywords"]');
    const keywordsTag = keywordsTagTemp ? keywordsTagTemp : document.createElement('meta');
    keywordsTag.setAttribute('name', 'keywords');
    keywordsTag.setAttribute('content', meta.keywords);
    document.head.appendChild(keywordsTag);
  }
  if (meta.description) {
    const descriptionTagTemp = document.querySelector('meta[name="description"]');
    const descriptionTag = descriptionTagTemp ? descriptionTagTemp : document.createElement('meta');
    descriptionTag.setAttribute('name', 'description');
    descriptionTag.setAttribute('content', meta.description);
    document.head.appendChild(descriptionTag);
  }
}
